package bma.common.langutil.ai.stack;

/**
 * 
 * @author guanzhong
 * @since 1.0 (imported from BMA.ESP Project)
 * 
 * @param <RESP_TYPE>
 */
public abstract class AIStackFilter<RESP_TYPE> extends AIStackWrap<RESP_TYPE> {

	public AIStackFilter(AIStack<RESP_TYPE> delegate) {
		super(delegate);
	}

	public boolean successFilter(RESP_TYPE v) {
		return delegate().success(v);
	}

	@Override
	public boolean success(RESP_TYPE result) {
		try {
			return handleResult(result);
		} catch (Exception e) {
			return super.failure(e);
		}
	}

	@Override
	public boolean failure(Throwable t) {
		try {
			return handleException(t);
		} catch (Exception e) {
			return super.failure(e);
		}
	}

	protected boolean handleResult(RESP_TYPE result) {
		return super.success(result);
	}

	protected boolean handleException(Throwable t) {
		return super.failure(t);
	}
}
